<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class receiveMO extends CI_Controller {
	 
	function __construct()
	{
		parent::__construct();
		$this->load->library("soap");  
		$this->load->helper('url');
		//$ns = $this->config->item('namespace');
		$ns= site_url('ws/receiveMO');
		$server = new soap_server();
		$server->configureWSDL('Service',site_url());
		$server->wsdl->schemaTargetNamespace=$ns; 
		$this->load->model('transms_model'); 
		$server->register('receiveMO',
 		array('commandcode' => 'xsd:string', 'serviceid' => 'xsd:string', 'userid'=> 'xsd:string','message'=> 'xsd:string','requestid'=> 'xsd:string','username'=> 'xsd:string', 'password'=> 'xsd:string'),array('result' => 'xsd:string'), $ns,"$ns#receiveMO",'rpc','encoded','get MO');
 
		function receiveMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password){ 
			return new soapval('return','xsd:string',receiveMO::receiveMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password));
		}
		 
		if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
		$server->service($HTTP_RAW_POST_DATA);
		//$this->load->view('welcome_message');
	}
	
	public function index() { }
	
	//MO Processing 
	function receiveMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password){
		if($username == "south" && $password=="south.123!@#"){
			return "So thue bao ".$userId." da dang ky thanh cong !";
		}else {
			return "error";
		} 
	}
	
	public function sendMT($userId){
		$wsdl= site_url('http://203.113.137.176/mt-services/MTService?WSDL');  
		$client=new nusoap_client($wsdl, array('wsdl'));
		$param=array('userId' => '84902171891',  
		    		'serviceId' => '6076',  
		    		'commandCode'=> 'DKA', 
		    		'info'=> 'phamios',  
		    		'messageType'=> '1', 
		    		'contentType '=> '42325345',
					'requestId'=>'');
		$result = $client->call('ws_receiverMO', $param);
		if ($client->fault) {
		    echo '<h2>Fault</h2><pre>';
		    print_r($result);
		    echo '</pre>';
		} else {
			// Check for errors
		    $err = $client->getError();
		    if ($err) {
		        // Display the error
		        echo '<h2>Error</h2><pre>' . $err . '</pre>';
		    } else {
		        // Display the result
		        echo '<h2>Result</h2><pre>';
		        print_r($result);
		    echo '</pre>';
		    }
		}
		
		// Display the request and response
		echo '<h2>Request</h2>';
		echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
		echo '<h2>Response</h2>';
		echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
		// Display the debug messages
		echo '<h2>Debug</h2>';
		echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';

		//echo $client->getError();
		//$this->load->view('welcome_message');
	}
	
	
	
	 
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */